/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import com.openbravo.data.loader.TableDBSentenceBuilder;
import e.odbo.data.dao.ModifiedLogDAO;
import com.openbravo.bean.Role;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.ImageUtils;
import com.openbravo.data.loader.sentence.StaticSentence;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import com.openbravo.pos.bean.AppUserExt;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class UserExtDAO extends ModifiedLogDAO<AppUserExt>{
    
    public UserExtDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return  new TableDefinition(
            "PEOPLE",
            new Field[]{
                   new Field("ID",Datas.STRING,Formats.STRING),
                   new Field("NAME",Datas.STRING,Formats.STRING),
                   new Field("APPPASSWORD",Datas.STRING,Formats.STRING),
                   new Field("ROLE",Datas.STRING,Formats.STRING,Role.class),// AppLocal.getIntString("label.role")),
                   new Field("VISIBLE",Datas.BOOLEAN,Formats.BOOLEAN),
                   new Field("CARD",Datas.STRING,Formats.STRING),
                   new Field("NUMBERID",Datas.STRING,Formats.STRING),
                   new Field("IMAGE", Datas.IMAGE,Formats.NULL),
                   new Field("LASTMODIFIED",Datas.TIMESTAMP,Formats.TIMESTAMP),
                   new Field("IMSI",Datas.STRING,Formats.STRING) 
                 },
              new int[] {0}
        );
    }

    @Override
    public void writeInsertValues(DataWrite dp, AppUserExt obj) throws BasicException {
          dp.setString(1,obj.getId());
          dp.setString(2,obj.getName());
          dp.setString(3, obj.getPassword());
          dp.setString(4, obj.getRole());
          dp.setBoolean(5,obj.isVisable());
          dp.setString(6,obj.getCard());
          dp.setString(7, obj.getNumber());   
          dp.setBytes(8, obj.getM_Image());
          dp.setTimestamp(9, obj.getLastModified());
          dp.setString(10, obj.getM_sIMSI());
    }

    public AppUserExt readValues(DataRead dr,AppUserExt obj) throws BasicException {
       if(obj==null)
    	   obj=new AppUserExt();
        obj.setM_sId(dr.getString(1));
        obj.setM_sName(dr.getString(2));
        obj.setM_sPassword(dr.getString(3));
        obj.setM_sRole(dr.getString(4));
        obj.setIsVisable(dr.getBoolean(5));
        obj.setM_sCard(dr.getString(6));
        obj.setM_sNumber(dr.getString(7)); 
        obj.setM_Image(dr.getBytes(8));
        obj.setLastModified(dr.getTimestamp(9));
        obj.setM_sIMSI(dr.getString(10));
        return obj;
          
    }

     public  final List listPeopleVisible() throws BasicException {
        return new StaticSentence(s
            , ((TableDBSentenceBuilder)getTableBuilder()).getListSQL(getTable())+" WHERE VISIBLE = " + s.getDialect().TRUE()
            , null
            , this).list();
    }
  
    @Override
    public Class getSuportClass() {
        return AppUserExt.class;
    }

}
